Trò chơi đua xe động vật trong UNITY Engine
114.823 lượt xem;
1 using UnityEngine;
2 using System.Collections;
3
4 public class ActionMoveTo : TemporalAction {
5
6 private float startX, startY;
7 private float endX, endY;
8
9 public ActionMoveTo(float x, float y, float duration)
10 {
11 SetMoveTo(x, y);
12 SetDuration(duration);
13 }
14
15 public ActionMoveTo(float x, float y, float duration, Interpolation interpolation)
16 {
17 SetMoveTo(x, y);
18 SetDuration(duration);
19 SetInterpolation(interpolation);
20 }
21
22 protected override void begin()
23 {
24 Vector3 position = actor.gameObject.transform.localPosition;
25 startX = position.x;
26 startY = position.y;
27 }
28
29 protected override void UpdateAction(float percent)
30 {
31 actor.gameObject.transform.localPosition = new Vector3(startX + (endX - startX) * percent, startY + (endY - startY) * percent, actor.gameObject.transform.localPosition.z);
32 }
33
34 private void SetMoveTo(float x, float y)
35 {
36 endX = x;
37 endY = y;
38 }
39
40 protected override void end()
41 {
42 }
43 }
2 using System.Collections;
3
4 public class ActionMoveTo : TemporalAction {
5
6 private float startX, startY;
7 private float endX, endY;
8
9 public ActionMoveTo(float x, float y, float duration)
10 {
11 SetMoveTo(x, y);
12 SetDuration(duration);
13 }
14
15 public ActionMoveTo(float x, float y, float duration, Interpolation interpolation)
16 {
17 SetMoveTo(x, y);
18 SetDuration(duration);
19 SetInterpolation(interpolation);
20 }
21
22 protected override void begin()
23 {
24 Vector3 position = actor.gameObject.transform.localPosition;
25 startX = position.x;
26 startY = position.y;
27 }
28
29 protected override void UpdateAction(float percent)
30 {
31 actor.gameObject.transform.localPosition = new Vector3(startX + (endX - startX) * percent, startY + (endY - startY) * percent, actor.gameObject.transform.localPosition.z);
32 }
33
34 private void SetMoveTo(float x, float y)
35 {
36 endX = x;
37 endY = y;
38 }
39
40 protected override void end()
41 {
42 }
43 }